package org.hda.dm.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateUtil {
    private static final String PATTERN = "yyyy-MM-dd HH:mm:ss";
    private static final String YTD = "yyyy-MM-dd";


    public static String dateToString(Date date) {
        if (date == null)
            return null;
        SimpleDateFormat dateFormat = new SimpleDateFormat(PATTERN);
        return dateFormat.format(date);
    }

    public static Date stringToDate(String str) {
        if (str == null || str.equals(""))
            return null;
        SimpleDateFormat dateFormat = new SimpleDateFormat(str);
        try {
            return dateFormat.parse(str);
        } catch (ParseException e) {
            e.printStackTrace();
            return null;
        }
    }

    public static String returnToday() {
        Date date = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat(YTD);
        String str = dateFormat.format(date);
        return str + " 00:00:00";
    }

    public static String returnTomorrow() {
        Date date = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat(YTD);
        String str = dateFormat.format(date);
        return str + " 23:59:59";
    }
}
